package com.changgou.search.controller;

import com.changgou.search.service.SkuInfoService;
import entity.Result;
import entity.StatusCode;
import org.apache.catalina.startup.RealmRuleSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @ClassName SearchController
 * @Description
 * @Author Mr.L
 * @Date 12:51 2019/11/16
 * @Version 2.1
 **/
@RestController
@RequestMapping("/search")
public class SkuInfoController {

    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 将数据库数据写入到索引库中
     */
    @GetMapping("/import")
    public Result importData(){
        skuInfoService.importSkuInfoToes();
        return new Result(true, StatusCode.OK,"数据导入成功");
    }

    /**
     * 检索
     * @param stringMap
     * @return
     */
    @GetMapping
    public Map<String, Object> search(@RequestParam(required = false) Map<String, String> stringMap){
        Map<String, Object> resultMap = skuInfoService.search(stringMap);
        return resultMap;
    }
}
